package cloud.xlh.auth.service.impl;

import cloud.xlh.auth.enums.CacheTypeEnum;
import cloud.xlh.auth.service.CommonService;
import cloud.xlh.auth.service.MessageService;
import cloud.xlh.auth.service.TokenService;
import cloud.xlh.auth.service.UserSecurityService;
import cloud.xlh.infrastructure.cache.operate.CacheOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/2/8 9:37
 * @ Description:
 */
@Service
public class UserSecurityServiceImpl implements UserSecurityService {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private MessageService messageService;
    @Resource(name = "Redis")
    private CacheOperateService redisCacheOperateService;
    @Resource(name = "Caffeine")
    private CacheOperateService caffeineCacheOperateService;
    @Autowired
    private CommonService commonService;

    @Override
    public TokenService getTokenService() {
        return tokenService;
    }

    @Override
    public CacheOperateService getCacheOperateService(Integer cacheTypeEnum) {
        if (CacheTypeEnum.CAFFEINE.getCode() == cacheTypeEnum) {
            return caffeineCacheOperateService;
        } else if (CacheTypeEnum.REDIS.getCode() == cacheTypeEnum){
            return redisCacheOperateService;
        } else {
            return redisCacheOperateService;
        }
    }

    @Override
    public MessageService getMessageService() {
        return messageService;
    }

    @Override
    public CommonService getCommonService() {
        return commonService;
    }
}
